﻿package frEngine.animateControler.uvControler
{
    import baseEngine.core.*;
    import flash.events.*;
    import frEngine.*;
    import frEngine.animateControler.*;
    import frEngine.animateControler.keyframe.*;
    import frEngine.event.*;
    import frEngine.shader.filters.*;
    import frEngine.shader.filters.fragmentFilters.*;
    import frEngine.shader.registType.*;

    public class SimpleWaterController extends MeshAnimateBase
    {
        private var _SimpleWaterParames:Array;

        public function SimpleWaterController()
        {
            this._SimpleWaterParames = new Array(0.005, 0.007, 0.003, 0.004, "water_normals.jpg", "water_normals1.jpg", "snow_positive_x.jpg", "snow_negative_x.jpg", "snow_positive_y.jpg", "snow_negative_y.jpg", "snow_positive_z.jpg", "snow_negative_z.jpg");
            return;
        }// end function

        override protected function setSurfaceHander(event:Event) : void
        {
            super.setSurfaceHander(event);
            this.regetRegister(null);
            FrEventDispatcher.instance.proxyAddEventListener(targetMesh.material, Engine3dEventName.MATERIAL_REBUILDER, this.regetRegister);
            return;
        }// end function

        private function regetRegister(event:Event) : void
        {
            var _loc_2:SimpleWaterNormalFilter = null;
            var _loc_3:FsParam = null;
            var _loc_4:FsParam = null;
            var _loc_5:FsParam = null;
            if (this.fcWaterMove)
            {
                this.fcWaterMove.value[0] = this.fcWaterMove.value[0] + this.SimpleWater[0];
                this.fcWaterMove.value[1] = this.fcWaterMove.value[1] + this.SimpleWater[1];
                this.fcWaterMove.value[2] = this.fcWaterMove.value[2] + this.SimpleWater[2];
                this.fcWaterMove.value[3] = this.fcWaterMove.value[3] + this.SimpleWater[3];
                if (targetMesh && targetMesh.material.materialParams.hasFilter(FilterType.SimpleWaterNormalFilter))
                {
                    _loc_2 = targetMesh.material.materialParams.getFilterByTypeId(FilterType.SimpleWaterNormalFilter) as SimpleWaterNormalFilter;
                    _loc_3 = targetMesh.material.getParam("{envMap}", false);
                    if (_loc_3)
                    {
                        _loc_3.value = _loc_2.cubeTex;
                    }
                    _loc_4 = targetMesh.material.getParam("{waveMap0}", false);
                    if (_loc_4)
                    {
                        _loc_4.value = _loc_2.waterMap1;
                    }
                    _loc_5 = targetMesh.material.getParam("{waveMap1}", false);
                    if (_loc_5)
                    {
                        _loc_5.value = _loc_2.waterMap2;
                    }
                }
            }
            return;
        }// end function

        override public function toUpdateAnimate(param1:Boolean = false) : void
        {
            super.toUpdateAnimate(param1);
            if (this.fcWaterMove)
            {
                this.fcWaterMove.value[0] = this.fcWaterMove.value[0] + this.SimpleWater[0];
                this.fcWaterMove.value[1] = this.fcWaterMove.value[1] + this.SimpleWater[1];
                this.fcWaterMove.value[2] = this.fcWaterMove.value[2] + this.SimpleWater[2];
                this.fcWaterMove.value[3] = this.fcWaterMove.value[3] + this.SimpleWater[3];
            }
            return;
        }// end function

        override public function dispose(param1:Boolean = true) : void
        {
            super.dispose();
            return;
        }// end function

        override protected function getBaseValue(param1:Pivot3D) : Object
        {
            return this._SimpleWaterParames;
        }// end function

        override public function get type() : int
        {
            return AnimateControlerType.SimpleWaterController;
        }// end function

        override protected function setTargetProperty(param1) : void
        {
            this.SimpleWater = param1 as Array;
            if (this.fcWaterMove)
            {
                this.fcWaterMove.value[0] = this.fcWaterMove.value[0] + this.SimpleWater[0];
                this.fcWaterMove.value[1] = this.fcWaterMove.value[1] + this.SimpleWater[1];
                this.fcWaterMove.value[2] = this.fcWaterMove.value[2] + this.SimpleWater[2];
                this.fcWaterMove.value[3] = this.fcWaterMove.value[3] + this.SimpleWater[3];
            }
            return;
        }// end function

        public function get SimpleWater() : Array
        {
            return targetMesh.material.materialParams.SimpleWaterParames;
        }// end function

        public function set SimpleWater(param1:Array) : void
        {
            if (targetMesh)
            {
                targetMesh.material.materialParams.SimpleWaterParames = param1;
            }
            return;
        }// end function

        public function get fcWaterMove() : FcParam
        {
            if (targetMesh)
            {
                return targetMesh.material.getParam("{fcWaterMove}", false);
            }
            return null;
        }// end function

    }
}
